<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="联入高度(m)" prop="lianRu">
				<u-input :border="border" placeholder="请输入联入高度" v-model="model.lianRu" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="底法兰及套管短节长度(m)" prop="diFaLan">
				<u-input :border="border" placeholder="请输入底法兰及套管短节长度" v-model="model.diFaLan" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
			
				<u-form-item v-if="model.taoBuJu" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="套补距" prop="taoBuJu">
					{{model.taoBuJu}} m
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">套补距 = 联入 - 底法兰及套管短节长度</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					lianRu: '',
					diFaLan: '',
					taoBuJu: ''
				},
				rules: {
					lianRu: [{
						required: true,
						message: '请输入联入高度',
						trigger: 'blur'
					}],
					diFaLan: [{
						required: true,
						message: '请输入底法兰及套管短节长度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 计算套补距
						this.model.taoBuJu = (parseFloat(this.model.lianRu) - parseFloat(this.model.diFaLan)).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>